﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GenericLibrary.Common
{
    //public abstract class Singleton2<T> where T : Singleton2<T>, new()
    //{
    //    private static T _instance = new T();

    //    public static T Instance
    //    {
    //        get
    //        {
    //            return _instance;
    //        }
    //    }

    //    protected Singleton2()
    //    {
    //        if (_instance != null)
    //        {
    //            throw new Exception();
    //        }
    //    }
    //}

    public abstract class Singleton<T> where T : Singleton<T>
    {
        private static T _instance;

        public static T Instance
        {
            get
            {
                return _instance;
            }
        }

        protected Singleton()
        {
            if (_instance != null)
            {
                throw new Exception();
            }
            _instance = this as T;
        }
    }
}
